package com.ybu.controller;

import com.ybu.common.Constants;
import com.ybu.common.JwtUtils;
import com.ybu.common.R;
import com.ybu.pojo.vo.FavoriteListVO;
import com.ybu.pojo.vo.ProductVO;
import com.ybu.pojo.vo.UserLoginVO;
import com.ybu.service.FavoriteListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestControllerAdvice
@RequestMapping("api/favorite")
public class FavoriteListController {
    @Autowired
        private FavoriteListService favoriteListService;

    @GetMapping("list")
    public R<List<FavoriteListVO>> getFavoriteList(HttpServletRequest request){
        String token = request.getHeader(Constants.TOKEN_HEADER);
        UserLoginVO userLoginVO = JwtUtils.parseToken(token);
        List<FavoriteListVO> favoriteList =favoriteListService.getFavoriteList(userLoginVO);
        return R.ok(favoriteList);
    }


}
